package cn.signalpha.modules.shop.controller.admin;

import cn.signalpha.common.constant.AppConstant;
import cn.signalpha.core.boot.ctrl.BaseController;
import cn.signalpha.core.tool.api.R;
import cn.signalpha.modules.shop.entity.SellerAddress;
import cn.signalpha.modules.shop.service.SellerAddressService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 控制器
 *
 * @author signalpha
 */
@RestController
@AllArgsConstructor
@RequestMapping(AppConstant.APPLICATION_SHOP_NAME + "/admin/seller/address")
@Api(value = "商户地址", tags = "商户地址")
public class SellerAddressController extends BaseController {

	private final SellerAddressService sellerAddressService;

	@GetMapping("/list")
	@ApiOperation(value = "列表", notes = "")
	public R<List<SellerAddress>> list(@RequestParam Long sellerId){
		List<SellerAddress> list = sellerAddressService.list(Wrappers.<SellerAddress>lambdaQuery()
			.eq(SellerAddress::getSellerId, sellerId)
			.orderByDesc(SellerAddress::getIsDefault).orderByDesc(SellerAddress::getId)
		);
		return R.data(list);
	}

	@GetMapping("/info")
	@ApiOperation(value = "详情", notes = "传入id")
	public R<SellerAddress> info(@RequestParam Long id){
		return R.data(sellerAddressService.getById(id));
	}

}
